package com.zky.gulimall.seckill.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * @Description redisson配置
 * @Author 张开源
 * @Date 2022/10/29 20:11
 * @Version 1.0
 **/
@Configuration
public class MyRedissonConfig {

    /**
     *
     * @return
     */
    @Bean(destroyMethod ="shutdown" )
    public RedissonClient redisson(@Value("${spring.redis.host}") String url){
        Config config = new Config();
        config.useSingleServer().setAddress("redis://"+url+":6379");
       return Redisson.create(config);
    }


    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }
}
